// Copyright 2005 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.tapestry5.internal.portlet.services;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletRequest;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import org.apache.tapestry5.internal.portlet.services.response.PortletResponse;
import org.apache.tapestry5.ioc.ScopeConstants;
import org.apache.tapestry5.ioc.annotations.Scope;
import org.apache.tapestry5.portlet.services.PortletRequestGlobals;

/**
 * Implementation of the tapestry.portlet.PortletRequestGlobals service, which
 * uses the threaded service lifecycle model.
 * 
 * @author Howard M. Lewis Ship
 * @since 4.0
 */
@Scope(ScopeConstants.PERTHREAD)
public class PortletRequestGlobalsImpl implements PortletRequestGlobals {

    private PortletRequest   _portletRequest;

    private PortletResponse  _portletResponse;

    private ActionRequest    _actionRequest;

    private ActionResponse   _actionResponse;

    private RenderResponse   _renderResponse;

    private RenderRequest    _renderRequest;

    private ResourceRequest  _resourceRequest;

    private ResourceResponse _resourceResponse;

    @Override
    public void storeActionRequestResponse(ActionRequest request, ActionResponse response) {
        this._actionRequest = request;
        this._actionResponse = response;
        this.store(request);
    }

    @Override
    public void storeRenderRequestResponse(RenderRequest request, RenderResponse response) {
        this._renderRequest = request;
        this._renderResponse = response;
        this.store(request);
    }

    @Override
    public void storeResourceResponseRequest(ResourceRequest request, ResourceResponse response) {
        this._resourceRequest = request;
        this._resourceResponse = response;
        this.store(request);
    }

    @Override
    public void storePortletResponse(PortletResponse response) {

        this._portletResponse = response;
    }

    private void store(PortletRequest request) {
        this._portletRequest = request;
    }

    @Override
    public PortletRequest getPortletRequest() {
        return this._portletRequest;
    }

    @Override
    public PortletResponse getPortletResponse() {
        return this._portletResponse;
    }

    @Override
    public ActionRequest getActionRequest() {
        return this._actionRequest;
    }

    @Override
    public ActionResponse getActionResponse() {
        return this._actionResponse;
    }

    @Override
    public RenderRequest getRenderRequest() {
        return this._renderRequest;
    }

    @Override
    public RenderResponse getRenderResponse() {
        return this._renderResponse;
    }

    @Override
    public ResourceRequest getResourceRequest() {
        return this._resourceRequest;
    }

    @Override
    public ResourceResponse getResourceResponse() {
        return this._resourceResponse;
    }

}
